// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "Widgets/SCompoundWidget.h"
#include "Widgets/Colors/SColorBlock.h"
#include "SCustomCurveList.generated.h"

#define M_PI 3.14159265358979323846

class USlateBrushAsset;
class SSlider;
class SProgressBar;

namespace Plugin_List
{
	class SCollisionScrollBox_List;
}

USTRUCT(BlueprintType)
struct FCustomCurveListInfo
{
	GENERATED_BODY()
public:
	FCustomCurveListInfo(float InOneValue, float InTwoValue, float InThreeValue, float InFourValue)
		: OneValue(InOneValue)
		  , TwoValue(InTwoValue)
		  , ThreeValue(InThreeValue)
		  , FourValue(InFourValue)
	{
	}
	FCustomCurveListInfo(){}
public:
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = OneInfo)
	float OneValue;
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = TwoInfo)
	float TwoValue;
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = ThreeInfo)
	float ThreeValue;
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = FourInfo)
	float FourValue;
};

class STextBlock_TextStyleLambda_List;
/**
 * 
 */
class LISTLIBRARY_API SCustomCurveList : public SCompoundWidget
{
public:
	SLATE_BEGIN_ARGS(SCustomCurveList)
			: _Title("")
			  , _TitleStrStyle("AlibabaRegular_12_83AAD6FF")
			  , _ColorOneInfo("")
			  , _ColorTwoInfo("")
			  , _ColorThreeInfo("")
			  , _ColorFourInfo("")
		{
		}

		SLATE_ARGUMENT(FString, Title)
		SLATE_ARGUMENT(FString, TitleStrStyle)
		SLATE_ARGUMENT(FString, ColorOneInfo)
		SLATE_ARGUMENT(FString, ColorTwoInfo)
		SLATE_ARGUMENT(FString, ColorThreeInfo)
		SLATE_ARGUMENT(FString, ColorFourInfo)
	SLATE_END_ARGS()
	
	virtual int32 OnPaint(const FPaintArgs& Args, const FGeometry& AllottedGeometry, const FSlateRect& MyCullingRect, FSlateWindowElementList& OutDrawElements, int32 LayerId, const FWidgetStyle& InWidgetStyle, bool bParentEnabled) const override;
	SCustomCurveList();
	/** Constructs this widget with InArgs */
	void Construct(const FArguments& InArgs);
	//更新数据表
	void UpDataList(TMap<FString, FCustomCurveListInfo> InListData);
	//自适应宽度数据表
	void UpdataCustomCurveList();
	//更改标题名字
	void UpDataTitleName(const FString InTitleName);
	void UpDataOneInfoName(const FString InOneInfoName);
	void UpDataTwoInfoName(const FString InTwoInfoName);
	void UpDataThreeInfoName(const FString InThreeInfoName);
	void UpDataFourInfoName(const FString InFourInfoName);
	void CleanList();

	//获取距离椭圆圆心半径某个角度的坐标
	/**
	 * @brief 
	 * @param CenterX 圆心X轴坐标
	 * @param CenterY 圆心Y轴坐标
	 * @param Width 椭圆宽
	 * @param Height 椭圆高
	 * @param angle 角度
	 * @param InPoint 返回的坐标点
	 */
	void GetEllipseOuterPoint(float CenterX, float CenterY, float Width,float Height, float angle, FVector2D &InPoint) const;
	//直线转曲线
	TArray<FVector2D> StraightLineToCurveLine(TArray<FVector2D> InStraightLine);
	//计算X轴上每个Y点的坐标
	TArray<FVector2D> GetAllYPoint(TArray<FVector2D> InStraightLine) const;
	virtual void Tick(const FGeometry& AllottedGeometry, const double InCurrentTime, const float InDeltaTime) override;
	//已知圆上两点和圆心角求圆心坐标(已验证算法可行,但是在此需求中显示效果并不好)
	FVector2D GetCenterPoint(FVector2D PointOne,FVector2D PointTwo,float Ang,bool IsPlusPlus);
	//通过圆上三点求圆心
	FVector2D tcircle(FVector2D pt1, FVector2D pt2, FVector2D pt3, float &radius);
public:
	//显示标题的字符串
	TSharedPtr<STextBlock_TextStyleLambda_List> TitleText;
	TSharedPtr<STextBlock_TextStyleLambda_List> OneInfo;
	TSharedPtr<STextBlock_TextStyleLambda_List> TwoInfo;
	TSharedPtr<STextBlock_TextStyleLambda_List> ThreeInfo;
	TSharedPtr<STextBlock_TextStyleLambda_List> FourInfo;

	TSharedPtr<SProgressBar> ProgressBar;
	TSharedPtr<SSlider> Slider;
	//是表格内容部分
	TSharedPtr<SBox> ListContent;
	TSharedPtr<Plugin_List::SCollisionScrollBox_List> ZhuScroll;
	TSharedPtr<Plugin_List::SCollisionScrollBox_List> TextScroll;
	//列表中所展示的数据
	TMap<FString, FCustomCurveListInfo> ListData;
	FCustomCurveListInfo BeginRand;
	FCustomCurveListInfo EndRang;
private:
	//更新数据后计算坐标
	bool SizeUpdata;
	//要绘制的起始坐标
	FVector2D BeginPoint;
	//绘制的区域
	FVector2D Size;
	TArray<FVector2D> OnePointS;
	TArray<FVector2D> TwoPointS;
	TArray<FVector2D> ThreePointS;
	TArray<FVector2D> FourPointS;
	
	TArray<FVector2D> OnePointY;
	TArray<FVector2D> TwoPointY;
	TArray<FVector2D> ThreePointY;
	TArray<FVector2D> FourPointY;

	TArray<FVector2D> CenterS;
public:
	//自定义的数值峰值
	int MaxValue;
	//区间
	int GrowValue;
	//柱子的个数
	int PillarNum;
	//使用曲线
	bool UseCurveLine;
	//显示面积
	bool ShowArea;
	//显示标题
	bool ShowTitle;
	//使用随机数
	bool UseRand;
	//使用刻度尺
	bool UseRuler;
	//用于绘制的区域
	TSharedPtr<SSpacer> SpacerDrawArea;
	USlateBrushAsset* BaiSlateBrush;
	USlateBrushAsset* LvSlateBrush;
	USlateBrushAsset* BlueSlateBrush;
	USlateBrushAsset* YellowSlateBrush;
};
